/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = cups_request.c                                                */
/*  NOTE      = cups request解析                                              */
/*  DATE      = 2015/03/18 by zhengxd                                         */
/******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>

#include "cups_core.h"
#include "cups_comm.h"
#include "cups_request.h"

//char arr_field_name[128][128];
extern void *g_p_apm_context;

/*******************************************************************************
*  FUNC     :  上报请求信息
*  ARGS     :  p_st_conn(入力链接信息)
*           :  p_st_private(私有session数据)
*           :  p_st_hash_report(保存Frreport_data)
*  RTN      :  APM_L7_ANALYZE_FAIL      (FAIL)
*              APM_L7_ANALYZE_SUCC      (SUCC)
*  NOTE     :
*******************************************************************************/
FR_STATIC int __cups_report_req(Conntrack *p_st_conn
                                , L7session_cups_private *p_st_private
                                , Frhash_header *p_st_hash_report)
{
    int i_ret = FR_SUCC;
    Frlist_node *p_st_node = NULL;
    cups_field_info *p_st_field = NULL;
    Frreport_data *p_st_report_data = NULL;
    Frreport_body_data *p_st_sess_body = NULL;
    L7_req_cups *p_st_req = p_st_private->p_st_req;
    L7_fragment_cups *p_st_fragment = p_st_private->p_st_fragment;
    char arr_key[256] = {0};
    char *p_channel = NULL;
    char *p_type_name = NULL;
    char *p_utf8_str = NULL;
    unsigned int ui_utf8_len = 0;
    unsigned int ui_key_len = sizeof(arr_key) - strlen(CUPS_REPORT_KEY_REQ) + 1;
    char *p_key = arr_key;
    snprintf(p_key, 256, "%s.", CUPS_REPORT_KEY_REQ);
    p_key += strlen(CUPS_REPORT_KEY_REQ) + 1;
    unsigned int ui_digits = 0;
    cpus_get_digits(p_st_req->ui_currency, &ui_digits);
    p_st_req->ul_req_sequence = frct_seq_increase(p_st_conn);

    /* 创建report body */
    p_st_sess_body = frreport_body_new_l7(p_st_conn);
    if (p_st_sess_body == NULL)
    {
        return APM_L7_ANALYZE_FAIL;
    }
    /* 追加connection相关信息 */
    i_ret = frreport_body_l7_add_connInfo(p_st_sess_body, p_st_conn);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    memcpy(p_st_req->arr_msg_type, p_st_fragment->arr_msg_type, CUPS_MSG_TP_LEN + 1);
    /* add title */
    i_ret = frreport_body_l7_add_str(p_st_sess_body
                                    , APM_REPORT_KEY_TRANS_TITLE
                                    , p_st_req->arr_msg_type);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    /* add sequence id */
    i_ret = frreport_body_l7_add_ulong(p_st_sess_body
                                      , APM_REPORT_KEY_REQ_ID
                                      , p_st_req->ul_req_sequence);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add isResponseRequired */
    i_ret = frreport_body_l7_add_int(p_st_sess_body
                                    , APM_REPORT_KEY_REQ_ISRESPREQUIRED, 1);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add request start time */
    p_st_req->st_start_timestamp = p_st_fragment->st_start_timestamp;
    i_ret = frreport_body_l7_add_timeval(p_st_sess_body
                                        , APM_REPORT_KEY_REQ_START_TIMESTAMP
                                        , &p_st_req->st_start_timestamp);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add request end time */
    p_st_req->st_end_timestamp = p_st_fragment->st_end_timestamp;
    i_ret = frreport_body_l7_add_timeval(p_st_sess_body
                                        , APM_REPORT_KEY_REQ_END_TIMESTAMP
                                        , &p_st_req->st_end_timestamp);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add send time */
    p_st_req->ul_send_time_us = cups_get_interval_time(&p_st_fragment->st_start_timestamp
                                                      , &p_st_fragment->st_end_timestamp);
    i_ret = frreport_body_l7_add_ulong(p_st_sess_body
                                      , APM_REPORT_KEY_REQ_SEND_TIME_US
                                      , p_st_req->ul_send_time_us);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add send data bytes */
    p_st_req->ul_request_bytes = p_st_fragment->ui_packet_len;
    i_ret = frreport_body_l7_add_ulong(p_st_sess_body
                                      , APM_REPORT_KEY_REQ_DATA_BYTES
                                      , p_st_req->ul_request_bytes);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    /* add message type */
    memcpy(p_st_req->arr_msg_type, p_st_fragment->arr_msg_type, sizeof(p_st_fragment->arr_msg_type));
    i_ret = frreport_body_l7_add_str(p_st_sess_body
                                    , CUPS_REPORT_KEY_REQ_MSG_TP
                                    , p_st_req->arr_msg_type);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    /* add trans info */
    memcpy(p_st_req->arr_trans_info, p_st_fragment->arr_trans_info, sizeof(p_st_fragment->arr_trans_info));
    i_ret = frreport_body_l7_add_str(p_st_sess_body
                                    , CUPS_REPORT_KEY_REQ_TRANS
                                    , p_st_req->arr_trans_info);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    /* add dest id */
    memcpy(p_st_req->arr_dest_id, p_st_fragment->arr_dest_id, sizeof(p_st_fragment->arr_dest_id));
    i_ret = frreport_body_l7_add_str(p_st_sess_body
                                    , CUPS_REPORT_KEY_REQ_DEST_ID
                                    , p_st_req->arr_dest_id);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    /* add src id */
    memcpy(p_st_req->arr_src_id, p_st_fragment->arr_src_id, sizeof(p_st_fragment->arr_src_id));
    i_ret = frreport_body_l7_add_str(p_st_sess_body
                                    , CUPS_REPORT_KEY_REQ_SRC_ID
                                    , p_st_req->arr_src_id);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }

    p_st_node = FRLIST_FIRST_NODE(&p_st_req->st_param);
    while (p_st_node)
    {
        p_st_field = (cups_field_info *)FRLIST_GET_NODE_DATA(p_st_node);
        /* 做成key */
        snprintf(p_key, ui_key_len, "%s"
                , cups_ret_value(p_st_field->ui_field_index - 1));
        /* 根据域号确定上报数据 */
        switch (p_st_field->ui_field_index)
        {
            case 3:
                i_ret = cups_get_type_name(p_st_field->p_field_value, &p_type_name);
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }

                i_ret = frreport_body_l7_add_str(p_st_sess_body, CUPS_REPORT_KEY_CONN_TYPE_CODE
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frfree(p_type_name);
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }

                i_ret = frreport_body_l7_add_str(p_st_sess_body, CUPS_REPORT_KEY_CONN_TYPE_NAME, p_type_name);
                frfree(p_type_name);
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 4:
            case 5:
            case 6:
                i_ret = cups_get_currency(&p_st_field->p_field_value, ui_digits);
                if (i_ret != APM_L7_ANALYZE_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 28:
                i_ret = cups_get_currency2(&p_st_field->p_field_value, ui_digits);
                if (i_ret != APM_L7_ANALYZE_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 38:
            case 41:
                frrtrim(p_st_field->p_field_value);
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 60:
                i_ret = cups_get_channel(p_st_field->p_field_value, &p_channel);
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                i_ret = frreport_body_l7_add_str(p_st_sess_body, CUPS_REPORT_KEY_CONN_CHANNEL, p_channel);
                frfree(p_channel);
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }

                /* add value */
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 11:
                i_ret = frreport_body_l7_add_str(p_st_sess_body, APM_REPORT_KEY_TRANS_CODE
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                /* add value */
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            case 43:
                frrtrim(p_st_field->p_field_value);
            case 61:
            case 62:
                if (p_st_field->p_field_value)
                {
                    /* 将参数信息转成UTF-8 */
                    i_ret = iconv_to_utf8(p_st_field->p_field_value
                                         , strlen(p_st_field->p_field_value)
                                         , "gb18030", &p_utf8_str, &ui_utf8_len);
                    if (i_ret == 2)
                    {
                        frreport_body_free(&p_st_sess_body);
                        return APM_L7_ANALYZE_FAIL;
                    }
                }
                else
                {
                    p_utf8_str = NULL;
                }
                /* add value */
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_utf8_str ? p_utf8_str : "");
                cups_free(&p_utf8_str);
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;

            default:
                /* add value */
                i_ret = frreport_body_l7_add_str(p_st_sess_body, arr_key
                                                , p_st_field->p_field_value ? p_st_field->p_field_value : "");
                if (i_ret != FR_SUCC)
                {
                    frreport_body_free(&p_st_sess_body);
                    return APM_L7_ANALYZE_FAIL;
                }
                break;
        }

        if (i_ret != FR_SUCC)
        {
            frreport_body_free(&p_st_sess_body);
            return APM_L7_ANALYZE_FAIL;
        }
        p_st_node = FRLIST_NEXT_NODE(p_st_node);
    }

    /* 创建report data header */
    p_st_report_data = frreport_data_l7_new(FRREPORT_TYPE_L7DATA_REQ);
    if (p_st_report_data == NULL)
    {
        frreport_body_free(&p_st_sess_body);
        return APM_L7_ANALYZE_FAIL;
    }
    /* add body into header */
    i_ret = frreport_data_add_body(p_st_report_data, p_st_sess_body);
    if (i_ret != FR_SUCC)
    {
        frreport_body_free(&p_st_sess_body);
        frreport_data_free(&p_st_report_data);
        return APM_L7_ANALYZE_FAIL;
    }

    /* 上报request数据 */
    i_ret = frreport_data_hash(p_st_hash_report, p_st_report_data);
    if (i_ret != FR_SUCC)
    {
        frreport_data_free(&p_st_report_data);
        return APM_L7_ANALYZE_FAIL;
    }

    return APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC);
}

/*******************************************************************************
*  FUNC     :  解析request
*  ARGS     :  p_st_conn (入力链接信息)
*           :  p_st_hash_report(Frreport_data)
*           :  p_st_private(cups交易私有数据)
*  RTN      :  参照module.h
*  NOTE     :
*******************************************************************************/
int cups_parse_request(Conntrack *p_st_conn
                        , L7session_cups_private *p_st_private
                        , Frhash_header *p_st_hash_report)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    char c_filed = 0;
    unsigned int ui_index = 0;
    unsigned int ui_loop = 0;
    unsigned int ui_field_index = 0;
    L7_req_cups *p_st_req = NULL;
    L7_fragment_cups *p_st_fragment = p_st_private->p_st_fragment;
    Frbyte_Packet *p_st_data = p_st_fragment->p_st_data;
    char arr_currency[3 + 1] = {0};

    if (p_st_private->p_st_req)
    {
        cups_destroy_request(&p_st_private->p_st_req);
    }

    p_st_req = (L7_req_cups *)frmalloc(sizeof(L7_req_cups));
    if (p_st_req == NULL)
    {
        return APM_L7_ANALYZE_FAIL;
    }
    memset(p_st_req, 0x0, sizeof(L7_req_cups));
    p_st_private->p_st_req = p_st_req;

    while (ui_index < p_st_fragment->ui_map_len)
    {
        c_filed = p_st_fragment->arr_map_bit[ui_index];
        for (ui_loop = 0; ui_loop < 8; ui_loop++)
        {
            /* 说明该域存在 */
            if ((c_filed << ui_loop) & 0x80)
            {
                ui_field_index = ui_index * 8 + ui_loop + 1;
                switch (ui_field_index)
                {
                    case 1:
                        frdbg("main map bit");
                        break;

                    case 2: //主账号
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 3: //交易处理码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 6, &p_st_req->st_param);
                        break;

                    case 4: //交易金额
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 12, &p_st_req->st_param);
                        break;

                    case 5: //清算金额
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 12, &p_st_req->st_param);
                        break;

                    case 6: //持卡人扣账金额
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 12, &p_st_req->st_param);
                        break;

                    case 7: //传输时间
                        i_ret = cups_create_datetime(p_st_data, ui_field_index
                                                      , &p_st_req->st_param);
                        break;

                    case 9: //清算汇率
                        i_ret = cups_create_rate(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                    case 10: //持卡人扣账汇率
                        i_ret = cups_create_rate(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                    case 11: //系统跟踪号
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 6, &p_st_req->st_param);
                        break;

                    case 12: //受卡方所在地时间
                        i_ret = cups_create_time(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 13:  //受卡方所在日期
                        i_ret = cups_create_date(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 14:  //卡有效期
                        i_ret = cups_create_date(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 15: //清算日期
                        i_ret = cups_create_date(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 16:  //兑换日期
                        i_ret = cups_create_date(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 18: //商户类型
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 4, &p_st_req->st_param);
                        break;

                    case 19: //商户国家代码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 22: //服务店输入方式码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 23: //卡序列号
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 25: //服务点条件码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 2, &p_st_req->st_param);
                        break;

                    case 26: //服务点PIN获取码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 2, &p_st_req->st_param);
                        break;

                     case 28: //交易费
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 9, &p_st_req->st_param);
                        break;

                    case 32: //受理机构标识码
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 33: //发送机构标识码
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 35: //第二磁道数据
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                  , &p_st_req->st_param);
                        break;

                    case 36: //第二磁道数据
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 37: //检索参考号
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 12, &p_st_req->st_param);
                        break;

                    case 38: //授权标识应答码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 6, &p_st_req->st_param);
                        break;

                    case 39: //应答码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 2, &p_st_req->st_param);
                        break;

                    case 41: //受卡机终端标识码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                    case 42: //受卡方标识码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 15, &p_st_req->st_param);
                        break;

                    case 43: //收卡方地址
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 40, &p_st_req->st_param);
                        break;

                    case 44: //附加响应数据
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 45: //Track 1 data
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 48: //自定义域
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 49: //交易货币代码
                        i_ret = bytebuff_get_bytes(p_st_data, arr_currency, 3);
                        if (i_ret != FR_SUCC)
                        {
                            return APM_L7_ANALYZE_FAIL;
                        }
                        i_ret = cups_str2len(arr_currency, 3, &p_st_req->ui_currency);
                        if (i_ret != FR_SUCC)
                        {
                            return APM_L7_ANALYZE_FAIL;
                        }

                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 50: //清算货币代码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 51: //持卡人账户货币代码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 52: //个人标识码数据
                        i_ret = cups_create_binary(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                    case 53: //安全控制信息
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 16, &p_st_req->st_param);
                        break;

                    case 54: //实际余额
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 55: //基于PBOC借贷记标准的IC卡数据域
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 57: //附加交易信息
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 58: //基于PBOC电子钱包/存折IC卡标准的交易数据
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 59: //明细查询数据
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 60: //自定义域
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 61: //持卡人身份证信息
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 62: //交换中心数据
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 63: //金融网络数据
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                    case 70: //网络管理码
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 3, &p_st_req->st_param);
                        break;

                    case 90: //原始数据元
                        i_ret = cups_create_bytes(p_st_data, ui_field_index
                                                   , 42, &p_st_req->st_param);
                        break;

                    case 96: //报文安全域
                        i_ret = cups_create_binary(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                    case 100: //接收机构标识
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 102: //账户标识1
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 103: //账户标识2
                        i_ret = cups_create_llvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 121:
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 122: //受理方保留
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 123: //发卡方保留
                        i_ret = cups_create_lllvar(p_st_data, ui_field_index
                                                   , &p_st_req->st_param);
                        break;

                     case 128: //报文鉴别码
                        i_ret = cups_create_binary(p_st_data, ui_field_index
                                                   , 8, &p_st_req->st_param);
                        break;

                     default:
                        i_ret = FR_FAIL;
                }
            }

            /* 解析失败 */
            if (i_ret == FR_FAIL)
            {
                frdbg("parse field[%d] failed\n", ui_field_index);
                return APM_L7_ANALYZE_FAIL;
            }
        }
        ui_index++;
    }

    frexpect2_add(g_p_apm_context, p_st_fragment->arr_dest_id, p_st_fragment->arr_src_id, p_st_conn);
    i_ret = __cups_report_req(p_st_conn, p_st_private, p_st_hash_report);
    return i_ret;
}
